<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<c:set var="module" value="design"/>
<style>
	.modal-backdrop.in {
    display: none;
}
</style>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
		<form action="${ctx }/admin/design/save?id=${n.id }" id="detail-form" class="form-horizontal" method="post" enctype="multipart/form-data" onsubmit="return save2()">
			<div class="form-group">
                 <label class="col-sm-2 control-label">设计师</label>
                 <div class="col-sm-10">
                 	<c:if test="${isDesigner }">
                 		<input type="hidden" id="user-id" name="user.id" value="${self.id }" class="form-control">
                 		<input type="text" class="form-control" value="${self.displayName }" readonly="readonly">
                 	</c:if>
                 	<c:if test="${not isDesigner }">
                 	<input type="hidden" placeholder="用户" id="user-id" name="user.id" value="${n.user.id }" class="form-control">
                 	<input type="text" class="form-control" id=displayName name="displayName" value="${n.user.realName }" 
                 		onclick="bring({
						                 	url:'${ctx}/admin/user/list?type=4',
						                 	name: 'displayName',
						                 	idInput: 'user-id',
						                 	nameInput: 'displayName'
						                 	})" />
                 	</c:if>
                 	
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">标题</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="title" value="${n.title }">
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-2 control-label">户型详情</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="details" value="${n.details }" placeholder="详情：客厅、厨房、主人房、客房、洗手间、储物室、衣帽间">
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-2 control-label">方案类型</label>
                 <div class="col-sm-10">
                 	<select class="form-control" name="type" id="designType">
                 		<c:forEach items="${designTypes }" var="dt">
                 			<option <c:if test="${n.type eq dt.value }">selected="selected"</c:if> value="${dt.value }">${dt.remark }</option>
                 		</c:forEach>
                 	</select>
                 </div>
             </div>	
	
			<div class="form-group" id="houseTypeDIV">
                 <label class="col-sm-2 control-label">户型</label>
                 <div class="col-sm-10">
                 	<select name="houseType.id" id="" class="form-control">
                 		<c:forEach items="${houseTypes }" var="t">
                 			<option value="${t.id }" ${n.houseType.id eq t.id ? 'selected' : '' }>${t.name }</option>
                 		</c:forEach>
                 	</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">风格</label>
                 <div class="col-sm-10">
                 	<select name="houseStyle.id" id="" class="form-control">
                 		<c:forEach items="${houseStyles }" var="t">
                 			<option value="${t.id }" ${n.houseStyle.id eq t.id ? 'selected' : '' }>${t.name }</option>
                 		</c:forEach>
                 	</select>
                 </div>
             </div>
			<div class="form-group">
                 <label class="col-sm-2 control-label">面积</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="area" value="${n.area }">
                 </div>
             </div>
            <div class="form-group" id="pdfDIV">
                 <label class="col-sm-2 control-label">方案PDF</label>
                 <div class="col-sm-10">
                 	<input type="file" class="form-control" name="pdfFile" value="${n.pdf }">
                 </div>
             </div>	
            <div class="form-group" id="view3dURLDIV">
                 <label class="col-sm-2 control-label">3DURL</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="view3dURL" value="${n.view3dURL }">
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-2 control-label">VRURL</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="VRURL" value="${n.VRURL }">
                 </div>
             </div>
             <div class="form-group">
                 <label class="col-sm-2 control-label">二维码</label>
                 <div class="col-sm-10">
                 		<input type="hidden" name="QRCode" id="QRCode" value="${n.QRCode }" />
                 	<div class="my-images" single="true" images="${n.QRCode }" id="image3" field="QRCode">
                 </div>
             </div>
             <div class="form-group" id="communityDIV">
                 <label class="col-sm-2 control-label">小区</label>
                 <div class="col-sm-10">
                 	<input type="hidden" class="form-control" id="community-id" name="community.id" value="${n.community.id }">
                 	<input type="text" class="form-control" id="community-name" name="community.name" value="${n.community.name }"
                 	onclick="bring({
						                 	url:'${ctx}/admin/community/list',
						                 	name: 'name',
						                 	idInput: 'community-id',
						                 	nameInput: 'community-name'
						                 	})" />
                 </div>
             </div>	
             <div class="form-group" id="communityHouseTypeDIV">
                 <label class="col-sm-2 control-label">小区户型</label>
                 <div class="col-sm-10">
                 	<input type="hidden" class="form-control" id="communityHouseType-id" name="communityHouseType.id" value="${n.communityHouseType.id }">
                 	<input type="text" class="form-control" id="communityHouseType-name" name="communityHouseType.name" value="${n.communityHouseType.name }">
                 </div>
             </div>			
			<div class="form-group">
                 <label class="col-sm-2 control-label">主题</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="theme" value="${n.theme }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">价格</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="price" value="${n.price }">
                 </div>
             </div>	
             <div class="form-group" id="contentDIV">
                 <label class="col-sm-2 control-label">内容</label>
                 <div class="col-sm-10">
                 	<input type="hidden" name="content" id="content"/>
                 	<div class="summernote">${n.content }</div>
                 </div>
             </div>
			<div class="form-group">
                 <label class="col-sm-2 control-label">封面图片</label>
                 <div class="col-sm-10">
                 	<%-- <input type="text" class="form-control" name="headImage" value="${n.headImage }"> --%>
                 	<!--  
                 	<input type="text" class="form-control" readonly id="headImage" name="headImage" value="${n.headImage }"
                 		onclick="bring4webuploader({idInput: 'headImage'})"/>
                 		<img src="" width="100"/>
                 	-->
                 	<input type="hidden" name="headImage" id="headImage" value="${n.headImage }" />
                 	<div class="my-images" single="true" images="${n.headImage }" id="image2" field="headImage">
                 </div>
             </div>	
             </div>
			<div class="form-group">
                 <label class="col-sm-2 control-label">详情图片</label>
                 <div class="col-sm-10">
                 	<%-- <input type="text" class="form-control" name="images" value="${n.images }"> --%>
                 	<!-- 
                 	<input type="text" class="form-control" readonly id="images" name="images" value="${n.images }"
                 		onclick="bring4webuploader({idInput: 'images'})"/>
                 		<img src="" width="100"/>
                 		 -->
                 	<input type="hidden" name="images" id="images" value="${n.images }" />
                 	<div class="my-images" single="false" images="${n.images }" id="image1" field="images">
                 </div>
             </div>	
        	</div>
        	<div class="form-group">
                 <label class="col-sm-2 control-label">是否推荐</label>
                 <div class="col-sm-10">
	        		<select name="recommend" class="form-control">
	               		<option value="1" ${n.recommend==1 ?'selected': '' }>推荐</option>
	                    <option value="0" ${n.recommend==0 ?'selected': '' }>不推荐</option>
	                </select>
                </div>
             </div>
		</form>
</div>

<%@include file="/common/foot.jsp" %>
<script type="text/javascript">
$(document).ready(function(){
	$("#communityHouseType-name").click(function(){
		var communityId= $("#community-id").val();
		bring({
         	url:'${ctx}/admin/communityHouseType/list?community.id=' + communityId,
         	name: 'name',
         	idInput: 'communityHouseType-id',
         	nameInput: 'communityHouseType-name'
         	})
	});
	
	init_images('image1');
	init_images('image2');
	init_images('image3');
	
	 function display() {
		 var designType = jQuery("#designType").find("option:selected").val();
		  if (designType == 2) {
			 	 $("#view3dURLDIV").hide();
				 $("#pdfDIV").show();
				 $("#contentDIV").hide();
				 $("#communityHouseTypeDIV").hide();
				 $("#communityDIV").hide();
				 $("#houseTypeDIV").show();
		  }
		  if (designType == 3) {
			  $("#view3dURLDIV").show();
				 $("#pdfDIV").hide();
				 $("#contentDIV").show();
				 $("#houseTypeDIV").hide();
				 $("#communityHouseTypeDIV").show();
				 $("#communityDIV").show();

		  }
		  if (designType == 1) {
			  $("#view3dURLDIV").hide();
				 $("#pdfDIV").hide();
				 $("#contentDIV").show();
				 $("#communityHouseTypeDIV").hide();
				 $("#communityDIV").hide();
				 $("#houseTypeDIV").show();
		  }
	 };
	 
	 display();
	 
	 
	  $("#designType").change(function(){
		 display();
	  });
	  
	  
	});

$('.summernote').summernote({
	  airMode: false,
	  lang: 'zh-CN',
	  height: 300,
	  callbacks: {
	    onChange: function(contents, $editable) {
	      save();
	    },
	    onImageUpload: function(files, editor, welEditable) {
	          for (var i = files.length - 1; i >= 0; i--) {
	          sendFile(files[i], editor, welEditable);
	       }
	  }
	 
 }
	});
	
	function save() {
		var html = $('.summernote').summernote('code');
	  	$('#content').val(html);
	  	console.log('save', html);
	  	return true;
	}
	save();
	
	function save2() {
		var html = $('.summernote').summernote('code');
	  	$('#content').val(html);	  
	  	return true;
	}
	
	
	  //create record for attachment
	  function sendFile(file, editor, welEditable) {
	    data = new FormData();
	    data.append("file", file);
	    $.ajax({
	        type: "POST",
	        url: "${ctx}/image/sm",
	        data: data,
	        cache: false,
	        contentType: false,
	        processData: false,
	        dataType: 'text',
	        success: function(url) {
	        	 $('.summernote').summernote('editor.insertImage', url);
	        	 save();
	        },
	        error : function(error) {
	        },
	        complete : function(response) {
	        }
	    });
	  }
	
	
	
</script>
</body>
</html>
